<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<!--{hook admin_page_list_start.htm}-->
<div class="container-fluid">
<div class="row">
    <div class="col-lg-12">
        <!--{hook admin_page_list_breadcrumb_before.htm}-->
        <?php if(empty($hide_breadcrumb)) { ?>
        <ol class="breadcrumb d-none d-md-flex text-muted border-left-primary">
            <li class="breadcrumb-item"><a href="./"><i class="icon-home text-primary" aria-hidden="true"></i></a></li>
            <li class="breadcrumb-item"><?php echo lang('single_page');?></li>
            <li class="breadcrumb-item"><?php echo lang('list');?></li>
            <!--{hook admin_page_list_breadcrumb.htm}-->
        </ol>
        <?php } ?>
        <!--{hook admin_page_list_breadcrumb_after.htm}-->

        <!--{hook admin_page_list_before.htm}-->
        <div class="card card-threadlist">
            <div class="card-body">
                <div class="d-flex justify-content-between mb-3">
                    <!--{hook admin_page_list_menu_start.htm}-->
                    <div>
                        <select class="custom-select mr-1 w-auto" name="fid" fid="<?php echo $fid;?>">
                            <!--{hook admin_page_list_select_strat.htm}-->
                            <option value="0"><?php echo 'sticky'==$route?lang('top_3'):lang('select'); ?></option>
                            <!--{hook admin_page_list_select_before.htm}-->
                            <?php foreach ($columnlist as $v) { ?>
                            <option value="<?php echo $v['fid']; ?>"><?php echo $v['name']; ?></option>
                            <?php } ?>
                            <!--{hook admin_page_list_select_end.htm}-->
                        </select>
                    </div>
                    <!--{hook admin_page_list_menu_end.htm}-->
                    <div>
                        <?php if (empty($columnlist)) { ?>
                        <a class="btn btn-danger btn-sm" href="<?php echo url('column-list', '', TRUE);?>"><?php echo lang('create').lang('column'); ?></a>
                        <?php } else { ?>
                        <a class="btn btn-danger btn-sm" href="<?php echo url('page-create', array('fid'=>$fid), TRUE);?>"><?php echo lang('increase').lang('content'); ?></a>
                        <?php } ?>
                    </div>
                    <!--{hook admin_page_list_menu_end.htm}-->
                </div>
                <ul class="list-unstyled threadlist mb-0">

                    <?php if($threadlist) { foreach($threadlist as &$_thread) { ?>
                    <li class="thread" tid="<?php echo $_thread['tid'];?>">

                        <div class="subject d-flex justify-content-between">
                            <div class="d-flex flex-row bd-highlight">
                                <?php if ($fid) { ?>
                                <input type="text" placeholder="<?php echo lang('well_rank');?>" name="rank" value="<?php echo $_thread['rank']; ?>" class="form-control small mr-2" rank="<?php echo $_thread['rank'];?>" tid="<?php echo $_thread['tid'];?>" style="width:45px;">
                                <?php } ?>
                                <h2 class="h6 text-break font-weight-bold mt-2 mb-0">
                                    <a href="<?php echo ($conf['url_rewrite_on'] < 2 ? '../' : ''),$_thread['url']; ?>" aria-label="<?php echo $_thread['subject'];?>"><?php echo $_thread['subject'];?></a>
                                </h2>
                            </div>

                            <div class="small manage">
                                <?php if( $_thread['allowupdate']) { ?>
                                <a href="<?php echo url('page-update', array('tid'=>$_thread['tid']), TRUE); ?>"><i class="icon-edit"></i> <?php echo lang('edit');?></a>
                                <?php } ?>
                                <?php if($_thread['allowdelete']) { ?>
                                <a class="confirm mx-1" data-method="post" data-confirm-text="<?php echo lang('confirm_delete');?>" href="<?php echo url('page-delete', array('tid'=>$_thread['tid']), TRUE);?>"><i class="icon-remove"></i> <?php echo lang('delete');?></a>
                                <?php } ?>
                            </div>
                        </div>
                    </li>
                    <?php }} else { ?>
                    <li class="list-group-item">
                        <div><?php echo lang('none');?></div>
                    </li>
                    <?php } ?>

                </ul>
            </div>
        </div>
        <?php if ($fid) { ?>
        <div class="text-center">
            <div class="btn-group mod-button my-3" role="group" aria-label="">
                <button class="btn btn-secondary rank" safe_token="<?php echo $safe_token;?>"><?php echo lang('rank');?></button>
            </div>
        </div>
        <?php } ?>
        <!--{hook admin_page_list_page_before.htm}-->
        <?php if ($pagination) { ?>
        <nav class="my-3"><ul class="pagination justify-content-center flex-wrap"><?php echo $pagination; ?></ul></nav>
        <?php } ?>
        <!--{hook admin_page_list_page_after.htm}-->
    </div>
</div>
</div>
<!--{hook admin_page_list_end.htm}-->

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script>
    let select = $('select[name="fid"]');
    select.val(select.attr('fid'));
    select.change(function () {
        let fid = $(this).val();
        window.location = xn.url('page-list', {fid:fid}, true);
    });

    $('button.rank').on('click', function () {
        let jthis = $(this);
        let rankarr = new Array();
        $('input[name="rank"]').each(function(){
            let tid = xn.intval($(this).attr('tid'));
            let oldrank = xn.intval($(this).attr('rank'));
            let rank = xn.intval($(this).val());
            rankarr.push({tid:tid,oldrank:oldrank,rank:rank});
        });
        $.xpost(xn.url('page-list', '', true), {'data':rankarr, 'safe_token':jthis.attr('safe_token')}, function (code, message) {
            if (code == 0) {
                $.alert(message);
                setTimeout(function() {
                    window.location.reload();
                }, 1000);
            } else {
                $.alert(message);
            }
        });
    });

    $('#content').addClass('show');
    $('li.content, .menu-page').addClass('active');
</script>

<!--{hook admin_page_list_js.htm}-->